<?php

namespace app\api\logic;

class School
{
    /**
     * 查询列表
     * @param array $param
     * @return array
     */
    public function getList($param = []): array
    {
        // 查询条件
        $where = [['status', '=', 1]];
        if (!empty($param['exam_id'])) {
            $where[] = ['exam_id', '=', $param['exam_id']];
        }
        if (!empty($param['province_id'])) {
            $where[] = ['province_id', '=', $param['province_id']];
        }
        if (!empty($param['name'])) {
            $where[] = ['name', 'like', '%' . $param['name'] . '%'];
        }

        // 查询数据
        $field = 'id,name';
        $list = app(\app\common\model\School::class)->field($field)->where($where)->cache(true)->select();

        // 返回
        return $list ? $list->toArray() : [];
    }
}